#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: splice03_category_dml.py 
@version:
@time: 2022/03/08 
"""
from TapClientCaseData.ColumnGenerateData.dynamic.splice06_sqlserver.splice04_sole_dml import *


# --------- CATEGORY ---------
def generate_category(args):
    tmp = []
    for i in args:
        tmp.append(str(i))
    return f"{', '.join(tmp)}"


def CATEGORY_INSERT_1(LIST):
    insert0 = ['pk']
    insert1 = ['1']
    for ONE in LIST:
        insert0.append(ONE.get('COLUMNS')[3:])
        insert1.append(ONE.get('INSERT_1')[3:])
    return [generate_category(insert0), generate_category(insert1)]


def CATEGORY_INSERT_2(LIST):
    insert0 = ['"pk"']
    insert1 = ['2']
    for ONE in LIST:
        insert0.append(ONE.get('COLUMNS')[3:])
        insert1.append(ONE.get('INSERT_2')[3:])
    return [generate_category(insert0), generate_category(insert1)]


def CATEGORY_UPDATE(LIST):
    TMP = {}
    for ONE in LIST:
        TMP.update(ONE.get('UPDATE'))
    return TMP


DML_SQLSERVER_NUMBER_CATEGORY = [
    DML_SQLSERVER_TINYINT,
    DML_SQLSERVER_SMALLINT,
    DML_SQLSERVER_INT,
    DML_SQLSERVER_BIGINT,
    DML_SQLSERVER_DECIMAL,
    DML_SQLSERVER_NUMERIC,
    DML_SQLSERVER_BIT,
    DML_SQLSERVER_SMALLMONEY,
    DML_SQLSERVER_MONEY,
    DML_SQLSERVER_FLOAT,
    DML_SQLSERVER_REAL,
]

DML_SQLSERVER_DATE_CATEGORY = [
    DML_SQLSERVER_DATE,
    DML_SQLSERVER_DATETIMEOFFSET,
    DML_SQLSERVER_DATETIME2,
    DML_SQLSERVER_SMALLDATETIME,
    DML_SQLSERVER_DATETIME,
    DML_SQLSERVER_TIME
]

DML_SQLSERVER_CHAR_CATEGORY = [
    DML_SQLSERVER_CHAR,
    DML_SQLSERVER_VARCHAR,
    DML_SQLSERVER_TEXT,
    DML_SQLSERVER_NCHAR,
    DML_SQLSERVER_NVARCHAR,
    DML_SQLSERVER_NTEXT
]

DML_SQLSERVER_BINARY_CATEGORY = [
    DML_SQLSERVER_BINARY,
    DML_SQLSERVER_VARBINARY,
    DML_SQLSERVER_IMAGE,
    DML_SQLSERVER_XML
]

DML_SQLSERVER_ALL = DML_SQLSERVER_NUMBER_CATEGORY + DML_SQLSERVER_DATE_CATEGORY + DML_SQLSERVER_CHAR_CATEGORY + \
                    DML_SQLSERVER_BINARY_CATEGORY
DML_SQLSERVER_ALL_INSERT_1 = CATEGORY_INSERT_1(DML_SQLSERVER_ALL)
DML_SQLSERVER_ALL_INSERT_2 = CATEGORY_INSERT_2(DML_SQLSERVER_ALL)
DML_SQLSERVER_ALL_UPDATE = CATEGORY_UPDATE(DML_SQLSERVER_ALL)
